import { defineStore } from 'pinia'

interface VegetablePrice {
  name: string
  prices: number[]
  currentPrice: number
}

export const useVegetableStore = defineStore('vegetables', {
  state: () => ({
    vegetables: [
      { name: '生菜', prices: [2.5, 2.3, 2.4, 2.6, 2.5, 2.7, 2.4], currentPrice: 2.4 },
      { name: '白菜', prices: [1.8, 1.9, 1.7, 2.0, 1.8, 2.1, 1.9], currentPrice: 1.9 },
      { name: '青椒', prices: [4.2, 4.0, 4.3, 4.1, 4.4, 4.2, 4.1], currentPrice: 4.1 },
      { name: '茄子', prices: [3.8, 3.9, 3.7, 3.8, 4.0, 3.9, 3.7], currentPrice: 3.7 },
      { name: '黄瓜', prices: [3.5, 3.2, 3.8, 3.5, 3.6, 3.9, 3.4], currentPrice: 3.4 },
      { name: '西红柿', prices: [4.2, 4.5, 4.3, 4.1, 4.4, 4.6, 4.2], currentPrice: 4.2 }
    ] as VegetablePrice[]
  }),
  actions: {
    updatePrice(name: string, newPrice: number) {
      const veg = this.vegetables.find(v => v.name === name)
      if (veg) {
        veg.currentPrice = newPrice
        veg.prices.shift()
        veg.prices.push(newPrice)
      }
    }
  }
}) 